﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Xts
{
    namespace XInterBank
    {
        namespace AuthorityClient
        {
            public class XLoginServerAgent_sync
            {
                protected Ice.Communicator x_ic;
                protected Ice.Logger x_logger;
                protected IXLoginServerPrx x_loginServerPrx;

                public bool IsValid { get { return x_loginServerPrx != null; } }

                public XLoginServerAgent_sync(ref Ice.Communicator ic, ref Ice.Logger logger)
                {
                    x_ic = ic;
                    x_logger = logger;
                    x_loginServerPrx = null;
                }

                public bool Initialize(string loginServerDsb)
                {
                    try
                    {
                        Ice.ObjectPrx objPrx = x_ic.stringToProxy(loginServerDsb);
                        x_loginServerPrx = IXLoginServerPrxHelper.checkedCast(objPrx);
                        return true;
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }
                    return false;
                }
                

                public XLoginRsp Login(XIdentityReq req)
                {
                    if(!IsValid)
                    {
                        x_logger.error("The XLoginServerAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_loginServerPrx.Login(req);
                    }
                    catch(Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
                public XOprtInfo Logout(XIdentityReq req)
                {
                    if (!IsValid)
                    {
                        x_logger.error("The XLoginServerAgent_sync object is NOT valid.");
                        return null;
                    }

                    try
                    {
                        return x_loginServerPrx.Logout(req);
                    }
                    catch (Ice.Exception ex)
                    {
                        x_logger.error(ex.Message);
                    }

                    return null;
                }
            }
        }
    }
    
}
